/**
 * 
 */
package me.magicall.db.sql.condition;

import me.magicall.db.sql.Operator;
import me.magicall.db.sql.expression.Expression;

/**
 * 一个条件中连接表达式的操作符
 * 
 * @author MaGiCalL
 */
public enum OneConditionOperator implements Operator<Expression<?>> {
	EQUALS("=", "!="), //
	GT(">", "<="), //
	LT("<", ">="), //
	IN(" IN ", " NOT IN "), //
	LIKE(" LIKE ", " NOT LIKE "), //
	GE(LT), //
	LE(GT), //
	NOT_EQUAL(EQUALS), //
	NOT_IN(IN), //
	NOT_LIKE(LIKE), //
	;
	static {
		final OneConditionOperator[] os = values();
		for (final OneConditionOperator o : os) {
			if (o.negativeOperator != null) {
				if (o.negativeOperator.negativeOperator == null) {
					o.negativeOperator.negativeOperator = o;
				}
			}
		}
	}
	private final String positiveSign;
	private final String negativeSign;
	private OneConditionOperator negativeOperator;

	private OneConditionOperator(final OneConditionOperator negativeOperator) {
		positiveSign = negativeOperator.negativeSign;
		negativeSign = negativeOperator.positiveSign;
		this.negativeOperator = negativeOperator;
	}

	private OneConditionOperator(final String positiveSign, final String negativeSign) {
		this.positiveSign = positiveSign;
		this.negativeSign = negativeSign;
	}

	@Override
	public String toSql() {
		return positiveSign;
	}

	@Override
	public StringBuilder appendTo(final StringBuilder sb) {
		return sb.append(positiveSign);
	}

	public OneConditionOperator getNegativeOperator() {
		return negativeOperator;
	}
}